package com.improvess.statistical;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

import Jama.Matrix;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
		Matrix[] conjuntoDeTreinamento = loadConjuntoDeTreinamento();
		final int numeroComponentes = 2;
		final int dimensao = 2;
		final double limiar = 0.00000001;
		EM em = new EM(numeroComponentes, dimensao, conjuntoDeTreinamento, limiar);
		Componente[] compoentes = em.execute();
		for(Componente componente : compoentes){
			System.out.println(componente);
			System.out.println();
		}
		System.out.println(EM.count);
	}

	private static Matrix[] loadConjuntoDeTreinamento() throws IOException {
		Matrix[] conjunto = new Matrix[200];
		FileInputStream fileInputStream = new FileInputStream(new File("train1.txt"));
		Scanner scanner = new Scanner(fileInputStream);
		scanner.nextDouble();
		scanner.nextDouble();
		int k = 0;
		while(scanner.hasNext()){
			double [][] valores = new double[2][1];
			valores[0][0] = scanner.nextDouble();
			valores[1][0] = scanner.nextDouble();
			scanner.next();
			
			Matrix matrix = new Matrix(valores);
			conjunto[k] = matrix;
			k++;
		}
		
		scanner.close();
		fileInputStream.close();
		
		return conjunto;
	}

}
